package tdd.t1;

import java.util.Iterator;
import java.util.List;

public class FeeMgr implements Charger{
	List<Charger> ch;
	public FeeMgr(List<Charger> ch) {
		this.ch = ch;
	}

	public String name() {
		return getClass().getSimpleName();
	}

	public double chargeByTime(double miles, int time) throws Exception {
		double fee = 0;
		if(miles<0||time<0||time>24) {
    		throw new Exception();
    	} 
		Iterator<Charger> it = this.ch.iterator();
		while(it.hasNext()) {
			fee += it.next().chargeByTime(miles, time);
		}
		return fee;
	}

	public double chargeByMiles(double miles) throws Exception {
		double fee = 0;
		if(miles<0) {
    		throw new Exception();
    	} 
		
		Iterator<Charger> it = this.ch.iterator();
		while(it.hasNext()) {
			fee += it.next().chargeByMiles(miles);
		}
		return fee;
	}
	

}
